<!DOCTYPE html>
<html lang="en">

{{ template "head.tpl.html" . }}

<script>
    // Constants
    const defaultAvatarUrl = 'assets/images/unknown.svg'
    const avatarUrlTemplate = {{ avatarUrlTemplate }}

    function guessTimezone() {
        return Intl.DateTimeFormat().resolvedOptions().timeZone
    }
</script>
<script type="module" src="assets/js/components/signup.js"></script>

<body class="bg-background text-muted p-4 pt-10 flex flex-col min-h-screen max-w-screen-lg mx-auto justify-center">

{{ template "header.tpl.html" . }}

{{ template "alerts.tpl.html" . }}

<main class="mt-10 grow flex justify-center w-full" id="signup-page">
    <div class="grow max-w-lg mt-10">
        <div class="mb-8">
            <h1 class="h1">Sign up to Wakapi</h1>
            <p class="text-secondary">
                Welcome to Wakapi! Your first step is to create an account.
                Afterwards, make sure to set up the <a href="https://wakatime.com" target="_blank" rel="noopener noreferrer" class="text-foreground hover:text-secondary">WakaTime</a> client tools.
                Instruction can be found in our <a href="setup" class="text-foreground hover:text-secondary">setup instructions</a> and the <a href="https://github.com/muety/wakapi#-client-setup" target="_blank"
                                   rel="noopener noreferrer"
                                   class="text-foreground hover:text-secondary">README</a>.
            </p>
        </div>
        <div>

        </div>

        <form class="mt-10" action="signup" method="post">
            <input type="hidden" name="location" id="input-location" v-model="timezone">
            <input type="hidden" name="captcha_id" value="{{ .CaptchaId }}">
            <input type="hidden" name="invite_code" id="input-invite-code" value="{{ .InviteCode }}">

            <div class="flex space-x-4">
                <div class="mt-1">
                    <img v-cloak id="avatar" :src="avatarUrl" width="96px" class="rounded-full border-4 border-accent cursor-pointer" alt="User Profile Avatar" title="Your Avatar"/>
                </div>

                <div>
                    <div class="mb-4">
                        <input class="input-default"
                               v-model="username"
                               type="text" id="username"
                               name="username" placeholder="Choose a username" minlength="1"
                               @keyup="updateAvatar"
                               required autofocus>
                    </div>
                    <div class="mb-4">
                        <input class="input-default"
                               v-model="email"
                               type="email" id="email"
                               name="email" @keyup="updateAvatar" placeholder="Your e-mail address">
                        <div class="text-xs text-muted mt-2">E-Mail address is optional, but required for some weekly reports and password reset.</div>
                    </div>
                </div>
            </div>
            <div class="mb-4">
                <input class="input-default"
                       type="password" id="password"
                       name="password" placeholder="Choose a password" minlength="6" required>
            </div>
            <div class="mb-4">
                <input class="input-default"
                       type="password" id="password_repeat"
                       name="password_repeat" placeholder="And again..." minlength="6" required>
            </div>
            {{ if .CaptchaId }}
            <div class="mb-4 flex">
                <img id="captchaimage" src="api/captcha/{{.CaptchaId}}.png" class="rounded-md" style="max-height: 64px; background: rgba(255, 255, 255, 0.75)" alt="Captcha image">
                <div class="flex-grow flex-col ml-4">
                    <input class="input-default"
                           v-model="captcha"
                           type="text" id="captcha"
                           name="captcha" placeholder="Verification"
                           required>
                    <div class="text-xs text-muted mt-1 ml-1 underline"><a href="https://github.com/muety/wakapi/issues/635" target="_blank" rel="noreferrer noopener">Why am I seeing this?<a></div>
                </div>
            </div>
            {{ end }}

            {{ if eq .TotalUsers 0 }}
            <p class="text-sm text-foreground mt-4 mb-8">
                ⚠️ <strong>Please note: </strong> Since there are no users registered in the system, yet, the first user will have administrative privileges, while additional users won't.
            </p>
            {{ end }}

            <div class="flex space-x-2 justify-end">
                <a href="login">
                    <button type="button" class="btn-default">Log in</button>
                </a>
                {{ if or (.AllowSignup) (ne .InviteCode "") }}
                <button type="submit" class="btn-primary">
                    Create Account
                </button>
                {{ else }}
                <button type="submit" class="btn-disabled" disabled title="The administrator of this instance has disabled sign up.">
                    Create Account
                </button>
                {{ end }}
            </div>
        </form>

        {{ if len .OidcProviders }}
        <div class="mt-10">
            <div class="font-semibold mb-2 text-secondary">Single Sign-On</div>
            {{ range $provider := .OidcProviders }}
            <a href="oidc/{{ $provider.Name | lower }}/login" class="block mb-2">
                <button type="button" class="btn-default w-full flex items-center gap-2 justify-center">
                    {{ if $.OidcProviderIcon $provider.Name }}
                    <span class="iconify inline text-white text-base" data-icon="{{ ($.OidcProviderIcon $provider.Name) | urlSafe }}"></span>
                    {{ end }}
                    Sign up {{ $provider.DisplayName }}
                </button>
            </a>
            {{ end }}
        </div>
        {{ end }}
    </div>
</main>

{{ template "footer.tpl.html" . }}

{{ template "foot.tpl.html" . }}

</body>

</html>
